package com.wuyou.simple;

import java.util.ArrayList;
import java.util.List;

public class AreNumbersAscending {


    public static void main(String[] args) {
//        String s = "1 box has 3 blue 4 red 6 green and 12 yellow marbles";
        String s =  "hello world 5 x 5";
//        String s = "sunset is at 7 51 pm overnight lows will be in the low 50 and 60 s";
        System.out.println(solution_2(s));
    }
    public static boolean solution_2(String s){
        List<String> list = new ArrayList<String>();
        int preNum = -1, beginIndex = 0, lastIndex = 0;
        String str = s;
        for (int i = 0; i < s.length(); i++) {
            if(s.charAt(i) == ' ' ){
                list.add(s.substring(beginIndex, i));
                beginIndex = i + 1;
                lastIndex = i;
            }
        }
        list.add(s.substring(lastIndex + 1));
        for (int i = 0; i < list.size(); i++) {
            if(list.get(i).charAt(0) >= '0' && list.get(i).charAt(0) <= '9'){
                int curNum = Integer.parseInt(list.get(i));
                if (preNum >= curNum) {
                    return false;
                }
                preNum = curNum;
            }

        }
        return true;
    }

    public static boolean solution_1(String s){
        String[] s1 = s.split(" ");
        int temp = -1;
        for (int i = 0; i < s1.length; i++) {
            if(s1[i].charAt(0) >= '0' && s1[i].charAt(0) <= '9'){
                int num = Integer.parseInt(s1[i]);
                if (num <= temp) {
                    return false;
                }
                temp = num;
            }
        }
        return true;
    }
}
